<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统公告管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="系统公告管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'title',width:80, align:'center'">标题</th>				
				<th data-options="field:'publishTime',width:80, align:'center'">发布日期</th>
				<th data-options="field:'content',width:260,align:'center'">内容</th>
				<th data-options="field:'id',width:100,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem');">新增</a>
		</div>
		<div>
			标题: <input class="easyui-textbox" type="text" id="title" style="width:150px;height:25px;">
			内容: <input class="easyui-textbox" type="text" id="content" style="width:150px;height:25px;">			
			发布日期：<input class="easyui-datebox"  id="publishTimeBegin" style="width:150px;height:25px;">
			~  <input class="easyui-datebox"  id="publishTimeEnd" style="width:150px;height:25px;">
			
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="系统公告详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:640px; height:350px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td width="70px" align="right">标题：</td>
						<td>
							<input class="easyui-textbox" id="lookTitle" readonly="readonly" style="width: 500px;" />
						</td>
					</tr>
					<tr>
						<td align="right">发布日期：</td>
						<td>
							<input class="easyui-datebox" id="lookPublishTime" style="width: 500px;" readonly="readonly">
						</td>
					</tr>
					<tr>
						<td align="right">内容：</td>
						<td>
							<input class="easyui-textbox" id="lookContent" style="width: 500px; height: 200px;" data-options="multiline:true" readonly="readonly" />
						</td>
					</tr>
					
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="发布系统公告" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:600px; height:330px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editPublicNotice" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td align="right">标题：</td>
							<td>
								<input class="easyui-textbox" name="title" data-options="required:true" style="width: 500px;" />
							</td>
						</tr>
						<tr>
							<td align="right">内容：</td>
							<td>
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 500px; height: 200px;" name="content">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑系统公告" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:600px; height:330px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editPublicNotice" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<input type="hidden" id="editPublisherId" name = "publisher.id">
					<input type="hidden" id="editPublishTime" name = "publishTime">
					<table width="100%" height="100%">
						<tr>
							<td align="right">标题：</td>
							<td>
								<input class="easyui-textbox" name="title" id="editTitle" data-options="required:true" style="width: 500px;" />
							</td>
						</tr>
						<tr>
							<td align="right">内容：</td>
							<td colspan="5">
								<input class="easyui-textbox" data-options="multiline:true, required:true" style="width: 500px; height: 200px;" name="content" id="editContent">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + row.id + ')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var title = $("#title").textbox("getValue").trim();
			var content = $("#content").textbox("getValue").trim();
			var publishTimeBegin = $("#publishTimeBegin").textbox("getValue").trim();
			var publishTimeEnd = $("#publishTimeEnd").textbox("getValue").trim();
			
			var url = "queryPublicNotice?publisherId=${currentUser.id}&title=" + title + "&content=" + content + "&publishTimeBegin=" + publishTimeBegin+ "&publishTimeEnd=" + publishTimeEnd;
			dg.datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			 	type: "GET",
			  	url: "findPublicNotice",
			  	data: params,
			  	success:function(data){
					var val = $.parseJSON(data);
	
					$("#lookPublisherId").text("setValue", val.publisherName);
					$("#lookTitle").textbox("setValue", val.title);
					$("#lookContent").textbox("setValue", val.content);
					$("#lookPublishTime").textbox("setValue", val.publishTime);
					
					$('#lookDetail').window('open');
			  	}
			});
		}
		function editItem(id){
			var params = "id=" + id;
			$.ajax({
			 	type: "GET",
			  	url: "findPublicNotice",
			  	data: params,
			  	success:function(data){
					var val = $.parseJSON(data);
					
					$("#editId").val(id);
					$("#editPublisherId").val(val.publisherId);
					$("#editPublishTime").val(val.publishTime);
					$("#editTitle").textbox("setValue", val.title);
					$("#editContent").textbox("setValue", val.content);
					
					$('#editItem').window('open');
			  	}
			});
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的系统公告吗？", function(r){
				if(r){
					var params = "id=" + id;
					$.ajax({
					  type: "GET",
					  url: "delPublicNotice",
					  data: params,
					  success:function(data){
						var val = $.parseJSON(data);
						if(val.success){
							bottomRight('提示', '操作成功！');
							$('#dg').datagrid('reload');
						}else{
							$.messager.alert("提示", val.msg, "error");
						}
					  }
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			search();
		});
	</script>
</body>
</html>